import api from '../../api';
import { message } from 'antd';
import config from '../../comps/business/tradingMarket/config';
import accounting from 'accounting';
export default {
  namespace: 'BackSellRegisterM',
  state: {},

  effects: {
    //获取回售登记表格内容
    *getTableData({ payload, callback }, { call, put }) {
      const res = yield call(api.BackSellRegister.getTableData, payload);
      if (res && res.data && JSON.stringify(res.data) != '{}' && res.code == 0) {
        res.data.columns &&
          res.data.columns.map((item) => {
            if (item.key == 'tradingname') {
              item.render = (text, record) => {
                return record.tradingcode + ' - ' + record.tradingname;
              };
            }
            if (item.key == 'exchangecode') {
              item.render = (text, record) => {
                let temp = undefined;
                config.map((item) => {
                  if (item.value == text) {
                    temp = item.title;
                  }
                });
                return temp;
              };
            }
            if (item.key == 'amount') {
              item.title = item.title + '（元）';
              item.type = 'money';
            }
            if (item.key == 'couponrate') {
              item.type = 'rate';
            }
          });
        res.data.dataSource &&
          res.data.dataSource.map((item) => {
            if (item.fundList && JSON.stringify(item.fundList) != '{}' && item.fundList.dataSource && item.fundList.dataSource.length > 0) {
              item.fundList.dataSource.map((item1) => {
                if (item1.fundName) {
                  item1.fundName = accounting.formatNumber(Number(item1.fundName) / 10000, 2);
                }
              });
            }
          });
        callback('success', res.data);
      } else {
        message.error(res.msg || '获取回售登记提醒数据失败');
      }
    },
  },

  reducers: {
    save(state, { payload }) {
      return {
        ...state,
        ...payload,
      };
    },
  },
};
